﻿(function(){
	var TabControl = function(){
		this.tabPanel = $("#tabPanel");
		this.nav = $("#nav");
	}
	$.extend(TabControl.prototype,{
		init:function(){
			var _this = this;
			this.nav.tree({
			    url: this.nav.attr("data-url"),
				method:"get",
				lines:true,
				onClick:function(node){
					if(node.url && node.url.length > 0){
						_this.add(node.text,node.url,node.id,node.icon);
					}
				}
			});
			this.tabPanel.on("dblclick",".tabs-header a",function(){
				_this.close($(this).find(".tabs-title").html());
			});
		},add:function(pTitle,pUrl,pId,pIcon){//添加tab页
			if(this.tabPanel.tabs("exists",pTitle)){
				this.tabPanel.tabs("select", pTitle);
			}else{
				this.tabPanel.tabs("add",{
					title:pTitle,
					content:'<iframe frameborder="no"  src="' + pUrl + '" style="width:100%;height:99%"></iframe>',
					iconCls:pIcon || 'icon-default'
				});
			}
		},close:function(pTitle){//关闭tab页
			this.tabPanel.tabs("close",pTitle);
		}
	})
	$(document).ready(function(){
		var Tab = new TabControl();
		Tab.init();
	})
})()